import { Component } from '@angular/core';

import { ToastController, NavController, AlertController, Platform, ModalController } from 'ionic-angular';
import { Storage } from '@ionic/storage';
import { SettingFeedbackService } from './feedback.service';
import { Config } from '../../../providers/config';

import { Common } from '../../../providers/common';

import { EmailDetailService } from '../../email/detail/detail.service';


@Component({
	selector: 'page-setting-feedback',
	templateUrl: 'feedback.html',
	providers: [SettingFeedbackService, EmailDetailService]
})
export class SettingFeedbackPage {
	moa_page_name: any = "page-setting-feedback";
  moa_page_explain: any = "意见反馈";

	constructor(
		public nav: NavController,
		public setttingFeedbackService: SettingFeedbackService,
		public emailDetailService: EmailDetailService,
		public alertCtrl: AlertController,
		public platform: Platform,
		public config: Config,
		public toastCtrl: ToastController,
		public modalCtrl: ModalController,
		public common: Common,
		public storage: Storage
	) {
	}

	feedback() {
		let content = document.getElementById("feedback-content")['value'];
		if (content.trim().length == 0) {
			let toast = this.toastCtrl.create({
				message: '请填写反馈内容',
				position: 'middle',
				duration: 2000,
				dismissOnPageChange: true
			});
			toast.present();
			return false;
		}

		if (this.platform.is('ios')) {
			content = content + "<br/><br/>（来自iPhone）"
		}

		if (this.platform.is('android')) {
			content = content + "<br/><br/>（来自Android）"
		}

		this.setttingFeedbackService.feedback({
			content: content
		}).subscribe(data => {
			if (data) {
				let alert = this.alertCtrl.create({
					title: '提示',
					subTitle: '意见反馈成功，非常感谢您宝贵的意见。',
					"buttons": ['确认']
				});
				alert.present();
				this.nav.pop();
			}
		});

	}
}
